package work.xiaohong.user.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置
 */
@Configuration
public class SwaggerConfig3 {
    private static Contact contact = new Contact();

    static {
        contact.setName("陈鸿");
        contact.setUrl("https://www.xiaohong.work/");
        contact.setEmail("1990063814@qq.com");
    }

    @Bean
    public OpenAPI ServerOpenAPI(@Value("${springdoc.version}") String appVersion) {
        return new OpenAPI()
                .components(new Components()
                        .addSecuritySchemes("Authorization", // key值，对应接口上方的name,也是验证规则的名字
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.APIKEY) //请求认证类型
                                        .name("xiaohong-token") //密钥名称 这里是请求头名称
                                        .description("token令牌") //描述
                                        .in(SecurityScheme.In.HEADER)
                        )//API密钥的位置。有效值"query","header"或"cookie"
                )
                .info(new Info()
                        .title("xxx微服务接口文档")
                        .description("本段为接口文档描述,下面是服务条款地址，最下面是许可证地址,你可以点[这里](https://www.xiaohong.work/)进官网")
                        .termsOfService("https://www.xiaohong.work/")
                        .version(appVersion)
                        .contact(contact)
                        .license(new License().name("陈鸿").url("https://www.xiaohong.work/")));
    }
}
